//
//  RichTableViewController.h
//  Rich
//
//  Created by Kenny Chen on 13/8/17.
//  Copyright (c) 2013年 Kenny Chen. All rights reserved.
//

#import "RichCore.h"
#import "FormatableDatePicker.h"

typedef enum {
    RichTableModeListEditable,
    RichTableModeListReadonly,
    RichTableModeCreate,
    RichTableModeUpdate,
    RichTableModeCustom
} RichTableMode;

typedef enum {
    RichTableCellStyleDefault = 0,
    RichTableCellStyleTextfield,
    RichTableCellStyleValue,
    RichTableCellStyleDetail,
    RichTableCellStyleButton,
    RichTableCellStyleMessage
} RichTableCellStyle;

enum {
    RichTableViewTagAccount     = 0x00010000,
    RichTableViewTagCategory    = 0x00020000,
    RichTableViewTagQuery       = 0x00040000,
    RichTableViewTagTransPicker = 0x00080000,
};

enum {
    RichPickerIdDefault = 0,
    RichPickerIdAccountType,
    RichPickerIdAccountProperty,
    RichPickerIdCurrency,
    RichPickerIdTransProperty,
    RichPickerIdInstallmentPeriod
};

enum {
    RichInputToolbarButtonDone = 1,
    RichInputToolbarButtonNext = 2,
    RichInputToolbarButtonBack = 4,
    RichInputToolbarButtonDefaultSet = RichInputToolbarButtonDone | RichInputToolbarButtonNext
};

@protocol RichTableViewControllerDelegate <NSObject>

- (void)didPressCreate;
- (void)didPressCreateDone;
- (void)didPressUpdateDone;

@end

@interface RichTableViewController : UITableViewController <UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate>
{
    FormatableDatePicker *  datePicker;
    UIPickerView *          defaultPicker;
    UIPickerView *          accountTypePicker;
    UIPickerView *          currencyPicker;
    UIPickerView *          accountPropertyPicker;
    UIPickerView *          transPropertyPicker;
    UIPickerView *          installmentPeriodPicker;
    
    UIToolbar *             inputToolbar;
    UIBarButtonItem *       toolbarBackButtonItem;
    UIBarButtonItem *       toolbarNextButtonItem;
    UIBarButtonItem *       toolbarDoneButtonItem;
    UIBarButtonItem *       toolbarFlexibleSpaceItem;
    
    UIBarButtonItem *       barDoneButtonItem;
    UIBarButtonItem *       barEditButtonItem;
    
    UITextField *           currentTextfield;
    NSMutableArray *        defaultPickerTitles;
    NSMutableArray *        accounts;
    NSMutableArray *        accountTypes;
    RichTableCellStyle      tableCellStyle;
    RootCategory            transPropCategory;
}

@property (nonatomic, assign) id<RichTableViewControllerDelegate> delegate;
@property (nonatomic, assign) UINavigationController *navigator;
@property (nonatomic, assign) UITableViewController <UITableViewDelegate> *callerDelegate;
@property (assign) RichTableMode mode;
@property (assign) NSInteger page;
@property (assign) NSInteger listSection;
@property (assign) NSInteger rowsNotAllowEditing;

// UI component init calls
- (void)initDatePicker;
- (void)initDefaultPicker;
- (void)initAccountTypePicker;
- (void)initAccountPropertyPicker;
- (void)initCurrencyPicker;
- (void)initTransPropertyPicker:(RootCategory)category;
- (void)initInstallmentPeriodPicker;
- (void)initInputToolbar:(NSUInteger)buttons;

// Default bar buttons
- (UIBarButtonItem *)barDoneButtonItem;
- (UIBarButtonItem *)barEditButtonItem;

- (void)textFieldDidChange:(UITextField *)textField;
- (void)tableViewDidPressCreateButton:(UIButton *)sender;
- (void)navBarDidPressDoneButton:(UIBarButtonItem *)sender;
- (void)navBarDidPressEditButton:(UIBarButtonItem *)sender;
- (void)toolbarDidPressDoneButton:(UIBarButtonItem *)sender;
- (void)toolbarDidPressNextButton:(UIBarButtonItem *)sender;
- (void)toolbarDidPressBackButton:(UIBarButtonItem *)sender;

@end

